package com.yiren.manager.service.impl.system;

import java.util.ArrayList;

import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.fasterxml.jackson.core.type.TypeReference;
import com.yiren.core.exception.MyException;
import com.yiren.core.service.GenericServiceImpl;
import com.yiren.core.utils.FavoriteSet;
import com.yiren.entity.YrAccountModelConfig;
import com.yiren.manager.form.system.YrAccountModelConfigForm;
import com.yiren.manager.repository.system.YrAccountModelConfigRepository;
import com.yiren.manager.service.iface.system.YrAccountModelConfigService;

@Service
public class YrAccountModelConfigServiceImpl extends GenericServiceImpl<YrAccountModelConfig, String> implements YrAccountModelConfigService{

	@Autowired
	public YrAccountModelConfigServiceImpl(YrAccountModelConfigRepository repository) {
		super(repository);
	}

	@Transactional
	public void allotRight(FavoriteSet favoriteSet) throws MyException {
		ArrayList<YrAccountModelConfig> accountModelConfigList = favoriteSet.getFavorite("accountModelConfigList",ArrayList.class);
		ArrayList<YrAccountModelConfig> deleteAccountModelConfigList = favoriteSet.getFavorite("deleteAccountModelConfigList", ArrayList.class);
		
		for(YrAccountModelConfig entity : deleteAccountModelConfigList){
			repository.delete(entity.getAccountModelConfigId());
		}
		
		for(YrAccountModelConfig entity : accountModelConfigList){
			repository.save(entity);
		}
	}

}
